package com.rocketmq;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.FileSystems;
import java.nio.file.Files;

/**
 * @author 歪大哥😁
 * @date 2019-12-14.
 */
public interface FileService {

    int write(ByteBuffer buf, String filePath);

    int read(ByteBuffer buf, String filePath);

    default File getOrCreateFile(String filePath) {
        File file = new File(filePath);
        if (!file.exists()) {
            try {
                Files.createFile(FileSystems.getDefault().getPath(filePath));
            } catch (IOException e) {
                return null;
            }
        }
        return file;
    }

}
